app.register.controller('StorageCtrl', function($scope, $http, $rootScope,
		$route, StorageSer, AppUtil,$routeParams) {
	
	loadFlag($routeParams.id,$scope);

	var page = AppUtil.GetLocalValue("storageTable_Page");
	var size = AppUtil.GetLocalValue("storageTable_Size");
	$scope.pagination = {
			totalItems :0,
		currentPage : page == undefined ? 1 : page,
		itemsPerPage : size == undefined ? 10 : size
	};
	$scope.showinfo={
			count1:12,
			count2:2,
			count3:3,
			count4:3,
			count5:2,
			count6:3,
			count7:2,
			count8:4,
			count9:4,
			count10:4
	};
	$scope.SearchData = function() {
		$scope.postData={};
		// 点击查询按钮时,恢复页码为1
		$scope.pagination.currentPage = 1
		// 表单查询参数
		var params = AppUtil.Params(".form_params");
		// 当有查询参数时,重置页数
		if (AppUtil.Length(params) > 0) {
			$scope.postData.params = params;
		}
		// 筛选查询参数
		var search_opt = AppUtil.GetSearchOpt();
		if (search_opt.length > 0) {
			$scope.postData.search_opt = search_opt;
		}
		LoadList();
	};
	// 加载数据方法
	var LoadList = function() {
		if ($scope.postData == undefined)
			$scope.postData = {};
		$scope.postData.page = $scope.pagination.currentPage;
		$scope.postData.size = $scope.pagination.itemsPerPage;
		// 加载数据
		StorageSer.list($scope.postData).success(function(response) {
			AppUtil.remove_loading();
			$scope.pagination.totalItems = response.total;
			$scope.datas = response.data;
			setTimeout(check_table_tr,500);
		});
	}

	// 配置分页监听
	$scope.$watch('pagination.refresh', LoadList);
	
	AppUtil.LoadGroups();
	$http.get("common/brands").success(function(data) {
		$scope.brands = data;
	});
	
	// 导出
	$scope.ExportData = function() {
		AppUtil.ExportData($scope.postData);
	};

});

app.register.service('StorageSer', function($http,AppUtil) {

	this.list = function(postData) {
		AppUtil.loading();
		postData.start = (postData.page - 1 < 0 ? 0 : postData.page - 1)
				* postData.size;
		return $http.post('carstorage/list', postData).error(function() {
			alertMsg("提示", "系统出错,请稍后重试.");
			AppUtil.remove_loading();
		});
	};

});
